package com.itheima.consumer.mq;


import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Component
public class SpringRabbitListener {

    @RabbitListener(queues = "simple.queue")
    public void listen(String msg){
        System.out.println("客户端接受的消息 = " + msg);
    }
    @RabbitListener(queues = "work.queue")
    public void listen2(String msg) throws InterruptedException {
        System.out.println("客户端1接受的消息 = " + msg);
        Thread.sleep(20);
    }
    @RabbitListener(queues = "work.queue")
    public void listen3(String msg) throws InterruptedException {
        System.err.println("客户端2接受的消息 = " + msg);
        Thread.sleep(200);
    }
//    @RabbitListener(queues = "hmall.queue1")
//    public void listenFanoutQueue1(String msg) {
//        System.out.println("消费者1接收到Fanout消息：【" + msg + "】");
//    }
//
//    @RabbitListener(queues = "hmall.queue2")
//    public void listenFanoutQueue2(String msg) {
//        System.out.println("消费者2接收到Fanout消息：【" + msg + "】");
//    }

//    @RabbitListener(queues = "direct.queue1")
//    public void listenDirectQueue1(String msg) {
//        System.out.println("消费者1接收到direct.queue1的消息：【" + msg + "】");
//    }
//
//    @RabbitListener(queues = "direct.queue2")
//    public void listenDirectQueue2(String msg) {
//        System.out.println("消费者2接收到direct.queue2的消息：【" + msg + "】");
//    }

//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "direct.queue1"),
//            exchange = @Exchange(name = "hmall.direct", type = ExchangeTypes.DIRECT),
//            key = {"red", "blue"}
//    ))
//    public void listenDirectQueue1(String msg){
//        System.out.println("消费者1接收到direct.queue1的消息：【" + msg + "】");
//    }
//
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "direct.queue2"),
//            exchange = @Exchange(name = "hmall.direct", type = ExchangeTypes.DIRECT),
//            key = {"red", "yellow"}
//    ))
//    public void listenDirectQueue2(String msg){
//        System.out.println("消费者2接收到direct.queue2的消息：【" + msg + "】");
//    }

    @RabbitListener(queues = "fanout.queue1")
    public void listenSimpleQueueMessage(Map<String, Object> msg) throws InterruptedException {
        System.out.println("消费者接收到object.queue消息：【" + msg + "】");
    }
}
